package com.compiler.lexico.action;

import java.io.IOException;
import java.io.RandomAccessFile;
import com.compiler.lexico.token.SymbolTable;
import com.compiler.lexico.token.Token;
import com.compiler.syntactic.Parser;

public class InsertOperator extends AbstractAction {
	private final static String TYPE="Operador";
	
	public InsertOperator(Token token, SymbolTable symbolTable) {
		super(token,symbolTable);
	}

	private int getParserVal() {
		int ret=-20;
		switch (this.token.getData()) {
		case ":=": ret = Parser.ASIGNACION;
			break;
		case "<=": ret = Parser.MENOR_IGUAL;
			break;
		case ">=": ret = Parser.MAYOR_IGUAL;
			break;
		case "<>": ret = Parser.DISTINTO;
			break;
		default:
			break;
		}
		return ret;
	}
	
	@Override
	public void exec(RandomAccessFile raf) throws IOException {
		if(token.getData().length() > 1)
			this.symbolTable.addToken(new Token(token.getData(),TYPE,token.getLine(),getParserVal()));
		else this.symbolTable.addToken(new Token(token.getData(),TYPE,token.getLine(),(int)this.token.getData().charAt(0)));
		this.token.clean();
	}

	@Override
	public String toString() {
		return "Insert";
	}

}
